package com.example.seh.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.seh.R;

import java.util.List;

public class SelectAdapter extends BaseAdapter {
    private Context mContext;
    private List<String> results;
    private int item;

    public SelectAdapter(Context mContext, List<String> results, int item) {
        this.mContext = mContext;
        this.results = results;
        this.item = item;
    }

    @Override
    public int getCount() {
        if (results != null) {
            return results.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        if (results != null) {
            return results.get(position);
        }
        return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoder viewHoder;
        if (null == convertView) {
            convertView = LayoutInflater.from(mContext).inflate(item, null);
            viewHoder = new ViewHoder();
            viewHoder.tvResult = convertView.findViewById(R.id.select_item);
            convertView.setTag(viewHoder);
        } else {
            viewHoder = (ViewHoder) convertView.getTag();
        }
        viewHoder.tvResult.setText(results.get(position));
        return convertView;
    }

    class ViewHoder{
        TextView tvResult;
    }
}
